import pandas as pd

data = pd.read_excel('data.xlsx', index_col='序号')
print(data.head())

import jieba

words = jieba.cut(data.loc[3, '评论内容'])
result = '/'.join(words)
print(result)

good = data[data['评分类型'] == '好评']
good = good['评论内容'].tolist()
good = ''.join(good)
good_seg_list = jieba.cut(good)

with open(file='stopwords.txt', mode='r', encoding='utf-8') as f:
    stopwords = f.read().splitlines()
extra_stopwords = [' ', '\n', '品牌', '商品', '沙发']
stopwords += extra_stopwords

good_filted = [w.lower for w in good_seg_list if w not in stopwords]

from collections import Counter

good_frq = Counter(good_filted).most_common(50)
print(good_frq)

import pyecharts.options as opts
from pyecharts.charts import WordCloud  # 导入词云模块

chart = WordCloud()
chart.add(series_name='数量', data_pair=good_frq, word_size_range=[10, 80])  # 添加数据'# 添加数据
chart.set_global_opts(
    title_opts=opts.TitleOpts(title='好评词云图', title_textstyle_opts=opts.TextStyleOpts(font_size=30)),
    tooltip_opts=opts.TitleOpts(is_show=True))
chart.render('good_wordcloud.html')  # 保存图片
